<div class="layui-fluid nepadmin-pad0 nepadmin-mar0 list0" id="list-select">
  <div class="layui-fluid">
    <div class="layui-row layui-col-space15" style="margin-top: 0;">
      <div class="layui-col-md12">
        <div class="layui-card" style="box-shadow: none;">
          <div class="layui-card-body">
			  
			<div>
				<button class="layui-btn layuiadmin-btn-lists" data-type="add">添加</button>
			</div>
            <table class="layui-hide" id="list-select-table" lay-filter="list-select-table"></table>
			<div id="list-select-toolbar" style="display: none;">
				<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
				<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
			</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
<div class="form-btn">
  	<input type="button" value="确认选择" class="layui-btn selectok">
   </div>
<script>
   //表格数据渲染
  var formurls='device_group/device_groupform',formareas=['500px', '650px'];
  layui.use(['table','form'], function () {
	  var table = layui.table
	  ,form = layui.form
	  ,$ = layui.$;
	  layui.admin.initlist(table,'device/group_list',195,[[
		{type:'radio'}
        ,{field:'device_group_id', title: 'ID', width:60}
        ,{field:'device_group_name', title: '分组名称', width:150}
        ,{field:'mode', title: '模式', width: 130}
        ,{field:'rule_name', title: '计费配置', width: 130}
        ,{field:'hotel', title: '酒店配置', width: 130}
        ,{field:'free_time', title: '免费时间(小时)', width:130}
		,{title:'操作', toolbar: '#list-select-toolbar', width:150}
      ]],'#list-select-table',415,{obj:layui.admin.device,val1:'device_group_id',val2:'group_id'})
	//监听表格操作事件
	table.on('tool(list-select-table)', function(obj){
	  var data = obj.data;
	  //删除
	  if(obj.event === 'del'){

		layer.confirm('确定删除'+data.device_group_name+'?', function(index){
		  layui.admin.ajax('device/group_delete',{device_group_id:data.device_group_id}).then(function(res){
			  layui.table.reload('list-select-table');
		  })
		});
	  } else if (obj.event === 'edit') { //编辑
			layui.admin.pupsc=layer.open({
				type:1,
			   id:'pup-contss',
			   title: '编辑分组',
			   btn:[],
			   area: formareas,
			   success: function(layero, index){
				   layui.admin.objDatas={detail:data,type:2};
				$('#pup-contss').load(layui.conf.views+formurls+layui.conf.engine);
			   }
			})
		}
	});
	var active = {
		add: function(othis){
			layui.admin.pupsc=layer.open({
				type:1,
			   id:'pup-contss',
			   title: '添加分组',
			   btn:[],
			   area: formareas,
			   success: function(layero, index){
				   layui.admin.objDatas={type:1};
				$('#pup-contss').load(layui.conf.views+formurls+layui.conf.engine);
			   }
			})
		}
	}; 
	//操作dom
	$('.layui-btn.layuiadmin-btn-lists').on('click', function(){
	  var type = $(this).data('type');
	  active[type] ? active[type].call(this) : '';
	});
	$('.selectok').click(function(){
			var checkStatus = table.checkStatus('list-select-table')
			,checkData = checkStatus.data[0];
			if(!checkData){
				layer.msg('请选择分组');
			}else{
				layui.admin.device.group_id=checkData.device_group_id;
				layui.admin.device.device_group_name=checkData.device_group_name;
				/* layui.admin.device.device_rule_id=checkData.device_rule_id;
				layui.admin.device.rule_name=checkData.rule_name; */
				layer.close(layui.admin.pups);
			}
		});
  });
</script>